# -*- coding: utf-8 -*-
# This example uses the implicit API, in the future we will have options unified which will make things easier.
# You can check if the unified methods are ready-to-use (createOrder, fetchOrder etc) by checking: `is_unified = exchange.has['option']`

import asyncio
import os
import sys
from pprint import pprint


import ccxt.async_support as ccxt  # noqa: E402


async def main():
    exchange = ccxt.binance(
        {
            "apiKey": "FC9r3f44u9UgPqnG5wzmW1FlTdUrzu8Bu1G3R18kyv1HdtNo7FedLgsuS3oo6bLH",
            "secret": "fjRHyLILCVw0uj29mFTribS94xeFw35SJXjYpkoCsEybPSFeOdrqyBgdzKZkGSBc",
            'verbose': True,  # for debug output
        }
    )
    await exchange.load_markets()
    market_id = "ETH-221028-1700-C"
    symbol = "ETH/USDT:USDT-221028-1700-C"
    timeframe = "30m"
    since = 1592317127349
    limit = 10
    try:
        response = await exchange.fetch_OHLCV(symbol, timeframe, since, limit)
        # Implicit API:
        # response = await exchange.eapiPublicGetKlines({
        #     'symbol': market_id,
        #     'interval': timeframe,
        #     # 'startTime': since,  # optional
        #     # 'limit': limit,  # optional
        # })
        pprint(response)
    except Exception as e:
        print("fetch_OHLCV() failed")
        print(e)
    await exchange.close()


asyncio.run(main())
